package com.alatus.config.converter;

import com.alatus.NetCrmServerApplication;
import com.alatus.model.TDicValue;
import com.alatus.result.DicEnum;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

import java.util.List;

public class NeedLoanConverter implements Converter<Integer> {
    @Override
    public Integer convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
//        把Excel转换为java数据
        String value = cellData.getStringValue();
        List<TDicValue> tDicValueList = (List<TDicValue>) NetCrmServerApplication.cacheMap.get(DicEnum.NEEDLOAN.getCode());
        for (TDicValue tDicValue : tDicValueList) {
            Integer id = tDicValue.getId();
            String name = tDicValue.getTypeValue();
            if(value.equals(name)){
                return id;
            }
        }
        return -1;
    }
}
